<div  style="width:100%;height: 100%">
    <div style="width: 300px;margin: 0 auto">
        <input id="bzZuZhangFormMonth" class= "easyui-datebox" data-options="label:'包装车间-考核月份',onSelect:bzMonthOnSelect,labelWidth:120,width:260"  required ="required">
    </div>
    <div id="bzcjDiv" style="width:100%;height: 96%">
        <div title="<span style='font-size:18px'>一线员工</span>" data-options="fit:true,iconCls:'icon-application-view-columns'"  style=" height:100%;padding:10px;display:none;">
            <!-- 加载页面 -->
            <div class="easyui-panel" style="height: 94%"  data-options="border:true,href:'/jx/jxAssess/bzcj/yiXianYuanGong.html'"></div>
            <!-- 一线员工 提交 -->
            <button id="yixianyuangongSubmit" style=" width:100%" class="opal-btn" onclick="">提交数据</button>
        </div>
        <div title="<span style='font-size:18px'>组长</span>" data-options="fit:true,iconCls:'icon-application-view-columns'" style=" height:100%;overflow:auto;padding:10px;display:none;">
            <!-- 加载页面 -->
            <div id="bzZuZhangPanel" style="height: 94%;"></div>
            <!-- 组长 提交 -->
            <button id="bzZuZhangSubmit" style=" width:100%" class="opal-btn" onclick="">提交数据</button>
<!--            <div  style="float: right" >-->
<!--                <a id="bzZuZhangSubmit" class="easyui-linkbutton" style="width: 80px;background-color:#00FF00" plain=true><i class="fa fa-check-circle fa-lg fa-fw"></i>提交</a>-->
<!--            </div>-->
        </div>
        <div title="<span style='font-size:18px'>辅助人员</span>" data-options="iconCls:'icon-application-view-columns'" style="padding:10px;display:none;">
            <!-- 加载页面 -->
            <div id="bzFuZhuRenYuanPanel" style="height: 94%;"></div>
            <!-- 辅助人员 提交数据 -->
            <button  style=" width:100%" class="opal-btn" onclick="bzchFuZhuRenYuanSubmit()">提交数据</button>
        </div>
        <div title="<span style='font-size:18px'>主管</span>" data-options="iconCls:'icon-application-view-columns'" style="padding:10px;display:none;">
            <!-- 加载页面 -->
            <div id="bzZhuGuanPanel" style="height: 88%;"></div>
            <div class="easyui-panel" style="width:100%;padding:5px;margin-bottom: 3px;text-align: right">
                <a href="#" class="easyui-linkbutton" data-options="toggle:true,group:'g2',plain:true">合计金额：</a>
                <input id="bzZhuGuanTatalMoneyInput" type="text" class="easyui-textbox" data-options="readonly:true" value="" style="width: 100px">
            </div>
            <!-- 主管 提交数据 -->
            <button id="bzZhuGuanSubmit" style=" width:100%" class="opal-btn" onclick="">提交数据</button>
        </div>
    </div>
    <script src="/js/jxAssess/jxAssessGlobalVariable.js"></script>
    <script src="/js/jxAssess/bzcj/bzcjIndex.js"></script>

    <script>
        //设置成当天,赋值datebox时间处理好难搞
        var date = new Date();
        $("#bzZuZhangFormMonth").val(date)
        bzcj_currentYear=date.getFullYear();
        bzcj_currentMonth=date.getMonth()+1;

        $('#bzcjDiv').tabs({
            border:false,
            justified:true,
           // pill:true,
            onSelect:function(title){
                if (title.indexOf(JX_BZCJ_ZUZHANG) !=-1){
                    $("#bzZuZhangPanel").panel({
                        border:true,
                        href:'/jx/jxAssess/bzcj/zuZhang.html',
                        onLoad:function (obj) {
                            bzSession(obj,title);
                        }
                    })
                }else if (title.indexOf(JX_BZCJ_FUZHURENYUAN) !=-1){
                    $("#bzFuZhuRenYuanPanel").panel({
                        border:true,
                        href:'/jx/jxAssess/bzcj/fuZhuRenYuan.html',
                        onLoad:function (obj) { //用户是否已过期
                            bzSession(obj,title);
                        }
                    })
                }else if (title.indexOf("主管") !=-1){
                    //查询数据库jx_assess_bzcj_zg中是否有本月的数据；按年月获取数据
                  var  bzCxZgColumnsAndDataInit= commonAjax("post","/jx/bzcj/getBzcjZhuGuanJxAssess",{year:bzcj_currentYear,month:bzcj_currentMonth})

                    if(bzCxZgColumnsAndDataInit.length>0){
                        $.messager.confirm('确认','本月（'+bzcj_currentYear+'年'+bzcj_currentMonth+'月）已有数据是否加载？',function(r){
                            if (!r){
                                //加载产线主管、辅助主管数据
                                bzCxZgColumnsAndDataInit=commonAjax("post","/jx/bzcj/selectJxEmpZhuGuanInfo",
                                    {year:bzcj_currentYear,month:bzcj_currentMonth,pkDept:bzcj_currentDept,postName:JX_BZCJ_FUZHUZHUGUAN+","+JX_BZCJ_ZHUGUAN})
                            }
                            //初始化页面
                            bzcjIndexBzZhuGuanPanel(bzCxZgColumnsAndDataInit,title)
                        });
                    }else {
                        //加载产线主管、辅助主管数据
                        bzCxZgColumnsAndDataInit=commonAjax("post","/jx/bzcj/selectJxEmpZhuGuanInfo",
                            {year:bzcj_currentYear,month:bzcj_currentMonth,pkDept:bzcj_currentDept,postName:JX_BZCJ_FUZHUZHUGUAN+","+JX_BZCJ_ZHUGUAN})
                        bzcjIndexBzZhuGuanPanel(bzCxZgColumnsAndDataInit,title)
                    }
                }
            }
        });

        function bzcjIndexBzZhuGuanPanel(bzCxZgColumnsAndDataInit,title){
            $("#bzZhuGuanPanel").panel({
                border:true,
                href:'/jx/jxAssess/bzcj/zhuGuan.html',
                onLoad:function (obj) {
                    //判断用户是否已过期
                    bzSession(obj,title);

                    //进页面执行方法
                    bzCxFzZhuGuanTableInit(bzCxZgColumnsAndDataInit);
                    //解析动态生成的组件
                    $.parser.parse($("#bzcjCxZhuGuanTableDiv"))
                }
            })
        }

        //一线员工提交数据
        $("#yixianyuangongSubmit").click(function () {
            var rows = $("#baoZhuangCheJianYiXianYuanGong").datagrid("getRows"); //返回当前页所有的信息
            var footer=$("#baoZhuangCheJianYiXianYuanGong").datagrid("getFooterRows"); //返回页脚行
            //获取年月
            rows.forEach(function (val) {
                val.assessYear=bzcj_currentYear;
                val.assessMonth=bzcj_currentMonth;
                val.assessDept=bzcj_currentDept;
                val.assessType=1; //设定一线员工类型为1
                val.postName=JX_BZCJ_YIXIANYUANGONG;
            })
            //把数据转换为json串
            rows=JSON.stringify({maps:footer,jxAssessBzcjs:rows})
            var resultMessage = commonAjax("post","/jx/bzcj/addAssessData",rows,"application/json;charset=utf-8");
            windowsOperation(null,null,resultMessage);

        })

        //组长提交数据
        $("#bzZuZhangSubmit").click(function () {
            var rows = $("#bzZuZhangTable").datagrid("getRows"); //返回当前页所有的信息
            var footer=$("#bzZuZhangTable").datagrid("getFooterRows"); //返回页脚行
            //获取年月
            rows.forEach(function (val) {
                val.assessYear=bzcj_currentYear;
                val.assessMonth=bzcj_currentMonth;
                val.assessDept=bzcj_currentDept;
                val.assessType=2; //设定组长绩效数据类型为2
                val.postName=JX_BZCJ_ZUZHANG;
            })
            //获取页脚行的数据：合计：班级的
            rows=JSON.stringify({maps:footer,jxAssessBzcjs:rows})
            var resultMessage = commonAjax("post","/jx/bzcj/addAssessData",rows,"application/json;charset=utf-8");
            windowsOperation(null,null,resultMessage);

        })
        //辅助人员提交数据
        function bzchFuZhuRenYuanSubmit() {
            //处理基本数据-----------------------------
            //获取辅助人员-普工的数据
            let fuZhuRenYuanTableData2=  $('#bzFuZhuRenYuanTable').datagrid("getRows")
            //由于js的破特性：fuZhuRenYuanTableData2数据引用的还是数据库获取的数据（恶心）
           let fuZhuRenYuanTableData=JSON.stringify(fuZhuRenYuanTableData2); //先转换为字符串
           fuZhuRenYuanTableData=JSON.parse(fuZhuRenYuanTableData);    //再解析回来，就不是引用了，赋值到另一个变量中
            //循环放入辅助人员数组中
            fuZhuRenYuanTableData.forEach(function (val) {
                val.assessYear=bzcj_currentYear;
                val.assessMonth=bzcj_currentMonth;
                val.assessDept=bzcj_currentDept;
                val.assessType=1; //设定辅助人员绩效数据类型为1
                val.postName=JX_BZCJ_FUZHURENYUAN;
                val.type=1;   //设置类型
            })
            //获取辅助组长的数据
            let zuZhang = $('#bzFuZhuZuZhangTable').datagrid("getRows")
            //循环放入辅助人员数组中
            zuZhang.forEach(function (val) {
                val.assessYear=bzcj_currentYear;
                val.assessMonth=bzcj_currentMonth;
                val.assessDept=bzcj_currentDept;
                val.assessType=2; //设定组长绩效数据类型为2
                val.postName=JX_BZCJ_FUZHUZUZHANG;
                fuZhuRenYuanTableData.push(val)
            })
            //获取辅助清洁工、搬运工的数据
            let zaGong=  $('#bzFuZhuZaGongTable').datagrid("getRows")
            //循环放入辅助人员数组中
            zaGong.forEach(function (val) {
                val.assessYear=bzcj_currentYear;
                val.assessMonth=bzcj_currentMonth;
                val.assessDept=bzcj_currentDept;
                val.assessType=3; //设定清洁工和搬运工绩效数据类型为3
                val.postName="杂工(清洁工|搬运工)";
                fuZhuRenYuanTableData.push(val)
            })
            //处理总合计-----------------
                  // 辅助人员
            let  totalNum=0;//三个类型的合计需要加起来
                //辅助人员的页脚行数据
            bzFuZhuRenYuanTableFooter.forEach(function (value) {
                let v=value.empCode;
                if (v.indexOf("合计")>0){
                    totalNum=Number(totalNum)+value.resultMoney;
                }
            })
                //辅助组长的页脚行数据
            let footer=$("#bzFuZhuZuZhangTable").datagrid("getFooterRows"); //返回页脚行
            totalNum=totalNum+ footer[0].resultMoney;
                //辅助杂工的页脚行数据
            let foot=$("#bzFuZhuZaGongTable").datagrid("getFooterRows"); //返回页脚行
            totalNum=totalNum+foot[0].resultMoney;
            //最终resultMoney的合计数据
            footer[0].resultMoney=totalNum
            let rows=JSON.stringify({maps:footer,jxAssessBzcjFzrys:fuZhuRenYuanTableData})
            let resultMessage = commonAjax("post","/jx/bzcj/addBzcjFuZhuRenYuan",rows,"application/json;charset=utf-8");

            //console.log("最终提交的数据：",rows)
            windowsOperation(null,null,resultMessage);
        }

        //包装车间--主管提交数据
        $("#bzZhuGuanSubmit").click(function () {
            //定义最终要提交数据变量
            let resultData={};
            let resultDataTemo=[];

            //获取辅助主管、产线主管每张表的数据
            bzcjCxFzZhuGuanTablesId.forEach(function (val) {
                var tableDatas = $("#"+val).datagrid("getRows");
                console.log(tableDatas.postName+"数据",tableDatas);
                for (var d of tableDatas){
                    d.assessYear=bzcj_currentYear;
                    d.assessMonth=bzcj_currentMonth;
                    d.assessDept=bzcj_currentDept;
                    if (d.postName==JX_BZCJ_FUZHUZHUGUAN){ //辅助主管
                        d.assessType=2; //设定辅助主管绩效数据类型为2
                    }else {
                        d.assessType=1; //设定辅助主管绩效数据类型为2
                    }
                    resultDataTemo.push(d);
                }
            })

            //获取总计划主管的数据
            var zZhuGuans=$("#bzcjTotalZhuGuanTable").datagrid("getRows");

            var zZhuGuan=zZhuGuans[0];
            zZhuGuan.assessYear=bzcj_currentYear;
            zZhuGuan.assessMonth=bzcj_currentMonth;
            zZhuGuan.assessDept=bzcj_currentDept;
            zZhuGuan.assessType=3;
            resultDataTemo.push(zZhuGuan)
            console.log("q全部表数据",resultDataTemo);
            //获取合计金额
            var totalMoney=$("#bzZhuGuanTatalMoneyInput").textbox("getValue");
            var jxAssessTotal={};
            jxAssessTotal.assessYear=bzcj_currentYear;
            jxAssessTotal.assessMonth=bzcj_currentMonth;
            jxAssessTotal.assessDept=bzcj_currentDept;
            jxAssessTotal.assessType=4;                       //主管的总合计类型是4
            jxAssessTotal.totalMoney=totalMoney
            resultData.jxAssessBzcjZgs=resultDataTemo;
            resultData.jxAssessTotal=jxAssessTotal;

            //保存数据
            var resultMessage=commonAjax("post","/jx/bzcj/saveZhuGuanAssessData",JSON.stringify(resultData),"application/json;charset=utf-8")
            windowsOperation(null,null,resultMessage);
        })

        //月份选择事件-往全局变量中赋值
        function bzMonthOnSelect(a) {
            bzcj_currentYear  =a.getFullYear();
            bzcj_currentMonth =a.getMonth()+1;
            //包装车间--辅助人员重新赋值
            if (window.bzFuZhuRenYuanALLData){
                var fuzhurenyuanchuancan=JSON.stringify({year:bzcj_currentYear,month:bzcj_currentMonth,
                    pkDept:bzcj_currentDept, maps:[{[JX_BZCJ_FUZHUZHUGUAN]:JX_BZCJ_FUZHUZHUGUAN_CODE, [JX_BZCJ_FUZHURENYUAN]:JX_BZCJ_FUZHURENYUAN_CODE,[JX_BZCJ_FUZHUZUZHANG]:JX_BZCJ_FUZHUZUZHANG_CODE}]})
                 bzFuZhuRenYuanALLData = commonAjax("post","/jx/bzcj/selectBzcjFuZhuRenYuan",fuzhurenyuanchuancan,"application/json;charset=utf-8");
            }

        }

        function bzSession(content,text) {
                if (content.indexOf("登录已过期，请重新登录！")!=-1) {
                    $('#bzcjDiv').tabs('close', text);
                    warnSessionConfirm();
                }
                if (content.indexOf("你没有权限！！")!=-1){
                    window.location.href = "/user/permissionDenied.html";
                }

        }
    </script>
</div>

